package com.mysoft.gfyx.common.rpc.opensearch.dto;

import com.mysoft.framework.common.exception.BusinessLogicException;
import com.mysoft.gfyx.common.util.MyStringUtil;
import lombok.Data;

import java.util.ArrayList;

@Data
public class SearchTakeLandRequestDto extends SearchBaseRequestDto {
    private String keyword;
    private String province;
    private String city;
    private String company_type;
    private String land_type;
    private String is_price_gt_avg;
    private String area_lower;
    private String area_upper;
    private String unit_price_lower;
    private String unit_price_upper;
    private String land_price_lower;
    private String land_price_upper;
    private String area;
    private String created_time;

    private String developer_top_100_label;
    private String new_area_expand_label;
    private String new_decorate_expand_label;
    private String new_land_usage_expand_label;
    private String price_gt_avg_label;

    private int page = 1;
    private int page_size;

    protected void setFilterByField(String field, String operatorType, Object value) {
        switch (field) {
            case "all_area":
                if ("ge".equals(operatorType) || "gt".equals(operatorType)) {
                    this.setArea_lower(value.toString());
                } else if ("le".equals(operatorType) || "lt".equals(operatorType)) {
                    this.setArea_upper(value.toString());
                }
                break;
            case "land_unit_price":
                if ("ge".equals(operatorType) || "gt".equals(operatorType)) {
                    this.setUnit_price_lower(value.toString());
                } else if ("le".equals(operatorType) || "lt".equals(operatorType)) {
                    this.setUnit_price_upper(value.toString());
                }
                break;
            case "take_land_price":
                if ("ge".equals(operatorType) || "gt".equals(operatorType)) {
                    this.setLand_price_lower(value.toString());
                } else if ("le".equals(operatorType) || "lt".equals(operatorType)) {
                    this.setLand_price_upper(value.toString());
                }
                break;
            case "land_usage":
                this.setLand_type(MyStringUtil.TranArrayToStr(operatorType, value).toString());
                break;
            case "company_type_label":
                this.dynamicSetPropertyByOperation("company_type", operatorType, value);
                break;
            case "tags_set":
                if (value instanceof ArrayList<?>) {
                    for (Object tag : (ArrayList<?>) value) {
                        this.setTags(tag.toString());
                    }
                } else {
                    this.setTags(value.toString());
                }
                break;
            case "province_code":
                this.dynamicSetPropertyByOperation("province", operatorType, value);
                break;
            case "city_code":
                this.dynamicSetPropertyByOperation("city", operatorType, value);
            default:
                this.dynamicSetPropertyByOperation(field, operatorType, value);
        }
    }

    protected void setTags(String tags) {
        switch (tags) {
            case "developer_top_100_label":
                this.setDeveloper_top_100_label("地产百强");
                break;
            case "new_decorate_expand_label":
                this.setNew_decorate_expand_label("新精装客群");
                break;
            case "new_land_usage_expand_label":
                this.setNew_land_usage_expand_label("新住宅客群");
                break;
            case "new_area_expand_label":
                this.setNew_area_expand_label("新区域拓展");
                break;
            case "price_gt_avg_label":
                this.setPrice_gt_avg_label("高端项目客群");
                break;
            default:
                throw new BusinessLogicException("未定义的标签" + tags);
        }
    }
}
